FROM ubuntu:22.04

WORKDIR /opt

#=== 基础库安装与Java、go、goreman、python安装
RUN apt-get update && apt-get install -y --no-install-recommends \
        curl apt-utils openssl build-essential ca-certificates pkg-config libglib2.0-dev valgrind \
        gdb vim automake autoconf libtool sudo git g++ gcc make libssl-dev dos2unix libhiredis-dev redis \
        libfmt-dev libssl-dev libevent-dev libdouble-conversion-dev libzstd-dev liblz4-dev \
        libsnappy-dev libjemalloc-dev ccache libjsoncpp-dev \  
        libgoogle-glog-dev libgflags-dev libgtest-dev \
        clang-14 libclang-14-dev \
        adduser libfontconfig1 musl libyaml-cpp-dev \
        libprotobuf-dev libprotoc-dev protobuf-compiler libleveldb-dev  libmsgpack-dev \
        lcov wget zlib1g zlib1g-dev libncurses5-dev liblzma-dev cmake \
        libboost-all-dev zookeeper libzookeeper-mt-dev \
        openjdk-11-jdk python3 python3-pip && \
        python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple && \
        update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
        wget https://dl.google.com/go/go1.18.3.linux-amd64.tar.gz && \
        tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz && \
        rm -rf go1.18.3.linux-amd64.tar.gz && \
        snapd && \
        apt-get clean -y

RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list && \
        echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
        echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
        echo "deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse" >> /etc/apt/sources.list && \
        apt-get update

ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
ENV GOROOT=/usr/local/go
ENV GOPATH=/go
ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
ENV GOPROXY=https://goproxy.cn,direct
ENV PATH="$JAVA_HOME/bin:$PATH"
ENV ANT_HOME=/usr
ENV PATH="$ANT_HOME/bin:$PATH"
ENV IVY_HOME=/usr/share/java
ENV PATH="$IVY_HOME:$PATH"

#=== 安装Ivy.jar、chaosblade、zookeeper等工具
RUN wget http://maven.aliyun.com/nexus/content/groups/public/org/apache/ivy/ivy/2.5.2/ivy-2.5.2.jar  -O /usr/share/java/ivy.jar && \
        wget https://github.com/chaosblade-io/chaosblade/releases/download/v1.7.4/chaosblade-1.7.4-linux-amd64.tar.gz && \
        tar -xzvf chaosblade-1.7.4-linux-amd64.tar.gz && \
        rm chaosblade-1.7.4-linux-amd64.tar.gz  && \
        wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.4/apache-zookeeper-3.8.4-bin.tar.gz && \
        tar -xzvf  apache-zookeeper-3.8.4-bin.tar.gz && \
        rm  apache-zookeeper-3.8.4-bin.tar.gz && \
        git clone https://github.com/brendangregg/FlameGraph.git && \
        go install github.com/mattn/goreman@latest && \
        # 安装prometheus
        wget https://github.com/prometheus/prometheus/releases/download/v2.54.1/prometheus-2.54.1.linux-amd64.tar.gz && \  
        tar -xzvf prometheus-2.54.1.linux-amd64.tar.gz && \
        rm -rf prometheus-2.54.1.linux-amd64.tar.gz && \
        mv prometheus-2.54.1.linux-amd64 prometheus && \
        # 安装redis_exporter
        wget https://github.com/oliver006/redis_exporter/releases/download/v1.66.0/redis_exporter-v1.66.0.linux-amd64.tar.gz && \
        tar -xzvf redis_exporter-v1.66.0.linux-amd64.tar.gz && \
        rm -rf redis_exporter-v1.66.0.linux-amd64.tar.gz && \
        mv redis_exporter-v1.66.0.linux-amd64 redis_exporter && \
        # 安装grafana
        wget https://dl.grafana.com/oss/release/grafana-11.4.0.linux-amd64.tar.gz && \
        tar -zxvf grafana-11.4.0.linux-amd64.tar.gz && \
        rm -rf grafana-11.4.0.linux-amd64.tar.gz && \ 
        mv grafana-v11.4.0 grafana && \
        /opt/grafana/bin/grafana-cli plugins install redis-datasource && \
        # 安装yq
        wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && \
        chmod +x /usr/bin/yq


#=== opensource
COPY install-opensource.sh /opt/install-opensource.sh
RUN dos2unix /opt/install-opensource.sh && chmod +x /opt/install-opensource.sh && /opt/install-opensource.sh

#=== 清理缓存文件
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
